﻿using System;
using FwtXnaGame3;
using GpgCore;
using GpgCore.Api;
using GpgCore.Corporations;
using GpgCore.GameWorld;
using GpgCore.Products;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GpgGame
{
    public static class GodObject
    {
        public static Planet Planet
        {
            get { return World.Instance.Planet; }
        }

        public static SpriteFont CellInfoFont;
        public static Vector2 PlanetMapSize = new Vector2(60);

        public static Corporation SelectedCorporation;
        public static CityOffice SelectedCityOffice
        {
            get { return SelectedCity.GetCityOffice(SelectedCorporation); }
        }
        public static City SelectedCity;

        static GodObject()
        {
            CreateSomePlanet();

            CellInfoFont = FwtGame3.Instanse.Content.Load<SpriteFont>("SmallFont");
        }

        private static void CreateSomePlanet()
        {
            MainFactory.CreateNewGame("Earth", new DateTime(1900, 1, 1), new Point(30, 30));

            var oilcell = World.Instance.Planet.PlanetMap.GetCell(9, 9);
            var ironcell = World.Instance.Planet.PlanetMap.GetCell(11, 10);
            var coalcell = World.Instance.Planet.PlanetMap.GetCell(11, 11);
            oilcell.Minerals = new Product(ProductType.Oil, 3000000);
            ironcell.Minerals = new Product(ProductType.IronOre, 3000000);
            coalcell.Minerals = new Product(ProductType.Coal, 3000000);

            //create england
            var england = MainFactory.CreateCountry("England");
            var londonCell = World.Instance.Planet.PlanetMap.GetCell(10, 10);
            var london = MainFactory.CreateCity("London", england, londonCell);

            //create corporation
            var freewebtime = MainFactory.CreateCorporation("Freewebtime");
            var fwtoffice = MainFactory.CreateCityOffice(freewebtime, london);
            fwtoffice.Money = 100000000;

            //mines
            var oilScheme = MiningScheme.FindScheme(ProductType.Oil);
            var ironScheme = MiningScheme.FindScheme(ProductType.IronOre);
            var coalScheme = MiningScheme.FindScheme(ProductType.Coal);
            var oilWells = MainFactory.CreateMine(oilcell, oilScheme, freewebtime);
            oilWells.WorkerPayment = 10;
            var ironMine = MainFactory.CreateMine(ironcell, ironScheme, freewebtime);
            ironMine.WorkerPayment = 10;
            var coalMine = MainFactory.CreateMine(coalcell, coalScheme, freewebtime);
            coalMine.WorkerPayment = 10;

            //farms
            var fscheme = FarmScheme.FindScheme(ProductType.Wheat);
            var wFarmCell = World.Instance.Planet.PlanetMap.GetCell(9, 10);
            var wFarmCell2 = World.Instance.Planet.PlanetMap.GetCell(9, 11);
            var wheatFarm = MainFactory.CreateFarm(wFarmCell, fscheme, freewebtime);
            wheatFarm.WorkerPayment = 10;
            var wheatFarm2 = MainFactory.CreateFarm(wFarmCell2, fscheme, freewebtime);
            wheatFarm2.WorkerPayment = 10;

            //factories
            var steelFactScheme = FactoryScheme.FindScheme(ProductType.Steal);
            var sfCell = World.Instance.Planet.PlanetMap.GetCell(8, 11);
            var steelFactory = MainFactory.CreateFactory(sfCell, steelFactScheme, freewebtime);
            steelFactory.WorkerPayment = 10;


            SelectedCity = london;
            SelectedCorporation = freewebtime;
        }
    }
}
